package com.crm.controller.enqController;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.crm.dao.OpportunityDAO;
import com.crm.entity.Business;
import com.crm.entity.Opportunity;

@Controller
@RequestMapping("/enqSearch")
public class SearchEnqController {
	protected final Log logger = LogFactory.getLog(getClass());
	//OpportunityDAO opportunityDAO=new OpportunityDAO();
	
	@RequestMapping("/open.do")
	public ModelAndView open(HttpSession session,ModelAndView model) throws Exception{
		Business bus=(Business)session.getAttribute("business");
		if(bus==null)return new ModelAndView("/jsp/index.jsp");
		int busid=bus.getBusinessId();
		
		List<Opportunity> lopp=OpportunityDAO.getSingleInstance().findAll(busid);
		return model=new ModelAndView("/jsp/search-enquiry.jsp")
		.addObject("menuName","enquiry")
		.addObject("submenu", "enquiry")
		.addObject("oppList",lopp);
	}
	@RequestMapping("/search.do")
	public ModelAndView search(HttpServletRequest request,HttpSession session,ModelAndView model) throws Exception{
		Business bus=(Business)session.getAttribute("business");
		if(bus==null)return new ModelAndView("/jsp/index.jsp");
		int busid=bus.getBusinessId();
		String month=request.getParameter("month");
		String year=request.getParameter("year");
		logger.info("Month Is:"+month);
		logger.info("Year Is:"+year);
		List<Opportunity> lopp= OpportunityDAO.getSingleInstance().getenqs(month, year, busid);
		return model=new ModelAndView("/jsp/search-enquiry.jsp")
		.addObject("menuName","enquiry")
		.addObject("submenu", "enquiry")
		.addObject("oppList",lopp);
	}
}
